//
//  BuyDetailViewController.m
//  PlayBall
//
//  Created by Jdd‘s macbook on 13-9-29.
//
//

#import "JddBuyDetailViewController.h"
#import "JddSfcRX9DetailViewController.h"
#import "JddBuyDetailTableViewController.h"

@interface JddBuyDetailViewController ()

@end

@implementation JddBuyDetailViewController

-(void)hideBSLblWithIsShow:(BOOL)isShow
{
    self.multipleLabel.hidden = isShow;
    self.bsLbl.hidden = isShow;
    self.bLbel.hidden = isShow;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.weishangchuanView.layer.borderColor = BORDER_COLOR;
    self.weishangchuanView.layer.borderWidth = 0.5;
    
    NSLog(@"%d",self.parentType);
    
    //如果是合买详情引用
    if (self.parentType == 1) {
        //隐藏背景的button
        self.bgBtn.hidden = YES;
        //隐藏方案内容文字
        self.faLbl.hidden = YES;
        //设置当前view
        CGRect viewFrame = self.view.frame;
        viewFrame.size.width = 300;
        viewFrame.size.height = 120;
        if (SCREEN_HEIGHT > 480) {
            viewFrame.size.height = 200;
        }
        self.view.frame = viewFrame;
        //设置view的contentView
        self.weishangchuanView.frame = viewFrame;
    //方案详情
    } else {
        CGRect viewFrame = self.view.frame;
        viewFrame.size.width = 300;
        viewFrame.size.height = 225;
        self.view.frame = viewFrame;
        self.weishangchuanView.frame = viewFrame;
    }
    
    //初始化数值
    [self initData];
}

//添加胜负彩任选9view
-(void)addSFCRX9ViewWithTableNumberList:(NSArray *)tableNumberList
{
    CGRect contentViewFrame = self.weishangchuanView.frame;
    contentViewFrame.origin.y = 21;
    contentViewFrame.size.height = 225-21;
    self.weishangchuanView.frame = contentViewFrame;
    JddSfcRX9DetailViewController *sfc = [[JddSfcRX9DetailViewController alloc] init];
    sfc.tableNumberList = tableNumberList;
    [self addChildViewController:sfc];
    //如果是合买详情引用
    if (self.parentType == 1) {
        //设置view的contentView
        CGRect wscViewFrame = self.weishangchuanView.frame;
        wscViewFrame.origin.x = 0;
//        wscViewFrame.size.width = 280;
        wscViewFrame.size.height = 80;
        if (SCREEN_HEIGHT > 480) {
            wscViewFrame.size.height = 147;
        }
        self.weishangchuanView.frame = wscViewFrame;
        
        //设置SFCview高度
        CGRect sFcviewFrame = sfc.view.frame;
        sFcviewFrame.size.height = 80;
        if (SCREEN_HEIGHT > 480) {
            sFcviewFrame.size.height = 147;
        }
        sFcviewFrame.size.width = 300;
        sfc.view.frame = sFcviewFrame;
    }
    [self.weishangchuanView addSubview:sfc.view];
    self.weishangchuanView.hidden = NO;
}

//添加其它彩种view
-(void)addBuyDetailTableViewWithTableNumberList:(NSArray *)tableNumberList AndSport:(int) sportType AndLottID:(int )lottID AndPlayTypeID:(int )playTypeID
{
    JddBuyDetailTableViewController *tableView = [[JddBuyDetailTableViewController alloc] init];
    tableView.tableNumberList = tableNumberList;
    tableView.sportType = sportType;
    tableView.lottId = lottID;
    tableView.playTypeID = playTypeID;
    tableView.playTypeName = self.playTypeName.text;
    [self addChildViewController:tableView];
    
    //设置tableView
    CGRect frame = tableView.view.frame;
    frame.origin.y = 0;
    
    //如果是合买详情引用
    if (self.parentType == 1) {
        //设置view的contentView
        CGRect wscViewFrame = self.weishangchuanView.frame;
        wscViewFrame.origin.y = 40;
        wscViewFrame.size.width = 300;
        if (SCREEN_HEIGHT > 480) {
            wscViewFrame.size.height = 160;
        } else {
            wscViewFrame.size.height = 80;
        }
        self.weishangchuanView.frame = wscViewFrame;
        
        frame.size.width = 300;
        if (SCREEN_HEIGHT > 480) {
            frame.size.height = 160;
        } else {
            frame.size.height = 80;
        }
        tableView.view.frame = frame;

    //方案详情引用
    }
    else {
        frame.size.width = 300;
        frame.size.height = 200;
        tableView.view.frame = self.weishangchuanView.frame;
    }
    tableView.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.weishangchuanView addSubview:tableView.view];
    self.weishangchuanView.hidden = NO;
}

-(void)initData
{
    //隐藏过关方式，玩法
    [self playLabelsHidden:YES];
    //初始化
    NSDictionary *tableValue = [[self.buydetail objectForKey:@"LotNumber"] objectFromJSONString];
    //tableView内容
   NSArray *tableNumberList = [tableValue objectForKey:@"item"];
    //倍数值
    self.multipleLabel.text = [[tableValue objectForKey:@"Multiple"] stringValue];
    //玩法
    self.playTypeName.text = [tableValue objectForKey:@"PlayTypeName"];
    //过关方式
    self.playLabel.text = [tableValue objectForKey:@"PassWay"];
    //是否可见
    BOOL iscancee = [[self.buydetail objectForKey:@"IsCanSee"] boolValue];
//   int isCanSee = [[self.buydetail objectForKey:@"IsCanSee"] intValue];
    int isCanSee = (iscancee == true? 1 : 0);
    //上传内容
    self.tipLabel.text = isCanSee == 0?[self.buydetail objectForKey:@"SecState"]:@"未上传";
   int lottID = [[self.buydetail objectForKey:@"LottID"] intValue];
   int playTypeID =  [[tableValue objectForKey:@"PlayTypeID"] intValue];

    NSString *isShow = [NSString alloc];
    if([self.buydetail objectForKey:@"IsShow"]){
        isShow = [self.buydetail objectForKey:@"IsShow"];
    }else{
        isShow = @"true";
    }

    if (![isShow boolValue]) {
        if (isCanSee != 0) {
            self.tipLabel.text = @"请至网站查看方案详情";
            self.faLbl.hidden = YES;
        }
        [self hideBSLblWithIsShow:YES];
        self.weishangchuanView.hidden = NO;
    }
    if ([tableNumberList count]==0 || isCanSee == 0) {
        [self hideBSLblWithIsShow:YES];
        self.weishangchuanView.hidden = NO;
    }
    //如果未上传的view隐藏时，添加tableView
    if (self.weishangchuanView.hidden == YES) {
    //判断胜负彩任选9
    NSString *lottName = [self.buydetail objectForKey:@"LottName"];
    NSRange rang = [lottName rangeOfString:@"胜负彩"];
    NSRange rang1 = [lottName rangeOfString:@"任选九"];
    if (![lottName isEqualToString:@"竞彩足球"] && ![lottName isEqualToString:@"竞彩篮球"]&& ![lottName isEqualToString:@"足彩单场"]) {
        if(rang.location != NSNotFound || rang1.location != NSNotFound){
            //添加胜负彩任选9view
            [self addSFCRX9ViewWithTableNumberList:tableNumberList];
            //过关方式和玩法是否显示
            [self playLabelsHidden:YES];
        }else{
            //过关方式和玩法是否显示
            [self playLabelsHidden:YES];
            //除了竞彩足球 竞彩篮球 北京单场意外的彩种
            [self addBuyDetailTableViewWithTableNumberList:tableNumberList AndSport:0 AndLottID:lottID AndPlayTypeID:playTypeID];
        }
    }else {
        //过关方式和玩法是否显示
        [self playLabelsHidden:NO];
        [self addBuyDetailTableViewWithTableNumberList:tableNumberList AndSport:1 AndLottID:lottID AndPlayTypeID:playTypeID];
    }
    }
    
}

//过关方式和玩法是否显示
-(void)playLabelsHidden:(BOOL)hidden
{
    self.playLabel.hidden =  hidden;
    self.playHeadLabel.hidden = hidden;
    self.playtypeLabel.hidden = hidden;
    self.playTypeName.hidden = hidden;
}



@end
